package com.caldremch.myhttp;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.SystemClock;

/**
 * @author Caldremch
 * @date 2018-09-03 15:21
 * @describe
 **/
public final class MyHttpUtils {

    private MyHttpUtils() {

    }
    @SuppressLint("StaticFieldLeak")
    private static Context sContext;

    private static long sServerTime = 0;
    private static long sLastGet = 0;


    public static void init(Context context) {
        sContext = context;
    }



    public static long getCurrentTime() {

        //第一次请求时， 服务器时间为0，
        if (sServerTime == 0) {
            //返回当前的系统时间
            return System.currentTimeMillis();
        } else {

            /*返回的服务器时间 + */
            return sServerTime + (SystemClock.elapsedRealtime() - sLastGet);
        }
    }

    public static Context getContext() {
        return sContext;
    }

    public static String getCheckSum(String data, long currentTime) {
        return EncryptUtils.getMD5(data + currentTime + "ZyxrAPIKey+6g2K3W5V67xJFdfbB8Qz");
    }

}
